package com.baitengsoft.patentservicemonitor.job.controller;


import com.baitengsoft.patentservicemonitor.common.utils.Res;
import com.baitengsoft.patentservicemonitor.job.cloud.AliyunCloudStorageService;
import com.baitengsoft.patentservicemonitor.job.cloud.CloudStorageConfig;

import com.baitengsoft.patentservicemonitor.job.task.PatentSynchroTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: KennyGu
 * @Date: 2018/1/10
 * @Description:
 */

@RestController
@RequestMapping("/aliyun/file")
@Api(value = "数据服务", description = "通过文件获取专利信息")
public class AliyunCloudController {
    @Autowired
    CloudStorageConfig config;
    @Autowired
    AliyunCloudStorageService aliyunCloudStorageService;

    @Autowired
    PatentSynchroTask patentSynchroTask;

    /**
     * 遍历平台初始化数据--区域内数据
     */
    @RequestMapping(value = "/initPatentListfor", method = RequestMethod.GET)
    @ApiOperation(value = "遍历平台初始化数据--区域内数据")
    public Res initPatentListfor(@RequestParam(value = "intPlatfromid") Integer intPlatfromid) {
        long startTime = System.currentTimeMillis();
        aliyunCloudStorageService.InitPatentListfor(intPlatfromid);
        long endTime = System.currentTimeMillis();
        System.out.printf("总共运行了多长时间:%s秒\r\n", (endTime - startTime) / 1000);
        return Res.ok();
    }

    /**
     * 遍历平台初始化数据--区域内转出数据
     */
    @RequestMapping(value = "/initPatentoutListfor", method = RequestMethod.GET)
    @ApiOperation(value = "遍历平台初始化数据--区域内转出数据")
    public Res initPatentoutListfor(@RequestParam(value = "intPlatfromid") Integer intPlatfromid) {
//        Integer intPlatfromid = 106;
//        Integer intJobId = 10;
        aliyunCloudStorageService.InitPatentoutListfor(intPlatfromid);
        return Res.ok();
    }


    /**
     * 更新数据
     */
    @RequestMapping(value = "/initPatentUpdateListfor", method = RequestMethod.GET)
    @ApiOperation(value = "更新数据")
    public Res initPatentUpdateListfor(@RequestParam(value = "intPlatfromid") Integer intPlatfromid) {
//        Integer intPlatfromid = 106;
//        Integer intJobId = 10;
        aliyunCloudStorageService.fileListbyupdate(intPlatfromid);
        return Res.ok();
    }


    @RequestMapping(value = "/initOssData", method = RequestMethod.POST)
    @ApiOperation(value = "初始化oss数据")
    public Res initOssData(@RequestParam(value = "param")String param,@RequestParam(value = "folder")String folder) {

        if (StringUtils.isBlank(param) || StringUtils.isBlank(folder)) {

            return Res.error("请输入参数");
        }

        patentSynchroTask.JobInitData(param, folder);
        patentSynchroTask.jobInitOutData(param, folder);
        return Res.ok();
    }


    /**
     * 测试
     */
//    @RequestMapping(value = "/test", method = RequestMethod.GET)
//    @ApiOperation(value = "测试")
//    public Res test() {
//
//        //AliyunCloudStorageService cloudStorageService=new AliyunCloudStorageService(config);
//
//
//        return Res.ok().put("test", aliyunCloudStorageService.fileList());
//    }
}
